<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>04运算符</title>
</head>
<body>
<script>
    //如果比较运算符左右两边有数字,会转为数字再进行比较
    console.log(3>10);
    console.log('3'>10);
    console.log(3>'10');
    console.log(Number('3'));
    console.log('3'>'10');
    console.log('3'.charCodeAt(0));
    console.log('10'.charCodeAt(0));

    //除法会根据实际结果显示运算结果
    console.log(3/2);
    console.log(6/2);

    let a = 1;
    let b = true;
    //松散比较运算符,只比较值,Number(true)=1
    console.log(a==b);//true
    //严格比较运算符,先比较类型,再比较值 number ≠ boolean
    console.log(a===b);//false

    //Number()将参数转换为数字,如果得不到数字结果,会得到NaN
    console.log(Number(true),typeof Number(true));
    console.log(Number('3'),typeof Number('3'));
    console.log(Number('你好'),typeof Number('你好'));//NaN(Not a Number) 'number'

    //Boolean()将参数转换为布尔值
    //如果参数为0,空字符串'',null,undefined,NaN返回false
    console.log(Boolean(0));//false
    console.log(Boolean(''));//false
    console.log(Boolean(null));//false
    console.log(Boolean(NaN));//false
    console.log(Boolean(undefined));//false
    console.log(Boolean(' '));//true
    console.log(Boolean('下午好!'));//true

    //三元运算符
    let c = 0;
    console.log(c==0 ? 'YES' : 'NO');
    console.log(c=0 ? 'YES' : 'NO');
</script>
</body>
</html>